﻿using Sc.Domain;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Sc.Persistence
{
    public class BaseItemTypeDAO
    {
        /// <summary>
        /// 获取分类信息
        /// </summary>
        /// <returns></returns>
        public IList<BaseItemType> GetList()
        {
            IList<BaseItemType> list = new List<BaseItemType>();
            string sql = " SELECT * FROM BaseItemType ";
            using (SqlDataReader dr = DbHelperSQL.ExecuteReader(sql))
            {
                while (dr.Read())
                {
                    try
                    {
                        BaseItemType obj = new BaseItemType();
                        obj.Id = (dr["Id"] == System.DBNull.Value ? 0 : dr.GetInt32(dr.GetOrdinal("Id")));
                        obj.Name = (dr["Name"] == System.DBNull.Value ? string.Empty : dr.GetString(dr.GetOrdinal("Name")));
                        list.Add(obj);
                    }
                    catch (Exception ex)
                    {
                        throw new Exception("从DataReader中读取数据失败，可能与相关的字段不存在有关！请检查！||" + ex.Message + "||" + ex.Source);
                    }
                }
                dr.Close();
            }
            return list;
        }
    }
}
